package com.holyn.guofang.presenter.login;

import com.holyn.guofang.model.webhttp.RetrofitManager;
import com.holyn.guofang.model.webhttp.observable.UserUnLoginObservable;
import com.holyn.guofang.model.webhttp.wo.StatusWo;
import com.holyn.guofang.presenter.BaseView;
import com.holyn.guofang.utils.MD5Uitl;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;

/**
 * Created by Holyn on 2017/6/12.
 */
//现在获取密码
public class GetPasswordPresent extends GetPasswordContract.Presenter{
    private final UserUnLoginObservable userUnLoginObservable;

    private GetPasswordContract.View getPasswordView;

    public GetPasswordPresent(@NonNull BaseView baseView) {
        super(baseView);
        userUnLoginObservable = RetrofitManager.getCommonObservable(UserUnLoginObservable.class);
    }

    @Override   //添加视图侦听器
    public void addViewListener(GetPasswordContract.View view) {
        this.getPasswordView = view;
    }

    @Override
    public void postPasswordCode(Integer checkMethod, String equipmentCode, final int requestAction) {
        getCommonObservable(requestAction, userUnLoginObservable.getPasswordCode(checkMethod, equipmentCode))
                .subscribe(new Consumer<StatusWo>() {
                    @Override
                    public void accept(@NonNull StatusWo statusWo) throws Exception {
                        getPasswordView.responseSuccess(requestAction, statusWo);
                    }
                });
    }

    @Override
    public void postChangePasswordCode(Integer checkMethod, String equipmentCode, String validCode, String password, final int requestAction) {
        getCommonObservable(requestAction, userUnLoginObservable.changePasswordCode(checkMethod, equipmentCode, validCode, MD5Uitl.getMd5Value(password)))
                .subscribe(new Consumer<StatusWo>() {
                    @Override
                    public void accept(@NonNull StatusWo statusWo) throws Exception {
                        getPasswordView.responseSuccess(requestAction, statusWo);
                    }
                });

    }
}
